home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8615 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Memcpy Problem
  5. Date: Tue, 05 Mar 96 12:28:48 GMT
  6. Organization: none
  7. Message-ID: <826028928snz@genesis.demon.co.uk>
  8. References: <Pine.OSF.3.91.960304161419.15251A-100000@alpha.fdu.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <Pine.OSF.3.91.960304161419.15251A-100000@alpha.fdu.edu>
  15.            rich@alpha.fdu.edu "Mr. Rich Reybok" writes:
  16.  
  17. >Hi.
  18. >        I'm writing a little program using BC 4.5, and I seem to have run 
  19. >into a bit of difficulty.
  20. >Here's the code snippet:
  21. >
  22. >{
  23. >char *temp="2592000"   
  24. >long l;
  25. >char temp2[100];
  26. >l=atol(temp)
  27. >memcpy(temp2,(char *)(&l),sizeof(l));
  28. >XXX(temp2,LONG_TYPE);
  29. >}
  30. >
  31. >where XXX is defined as XXX(void *value,int datatype);  XXX casts value 
  32. >as datatype.
  33.  
  34. If XXX is written sensibly its first argument would be a pointer to the
  35. variable concerned so you would just call it as:
  36.  
  37. XXX(&l, LONG_TYPE);
  38.  
  39. If internally XXX() simply casts its first argument to long then it is
  40. very poorly written and isn't portable. Your best chance of making it
  41. works is:
  42.  
  43. XXX((void *)l, LONG_TYPE);
  44.  
  45. > This code basically creates a long value out of a char * 
  46. >that it's gets from elsewhere in the program.  It should then copy the 
  47. >byte pattern of the long into a char * and send it to XXX.  However I get 
  48. >a memory problem and the debugger exits with error 9. I don't know what 
  49. >error 9 was,  couldn't find references to it anywhere :-(  If I change l 
  50. >to an int and use atoi everything works fine.  However I have one value 
  51. >that will always be a long so I need a solution.  Changing XXX is 
  52. >impossible, it is in an SDK I'm using.  Any suggestions?  Am I 
  53. >overlooking something between the long and int data types? 
  54.  
  55. I think you need to look more carefully at how XXX() is defined. There's
  56. not a lot more that can be said without knowing more about it.
  57.  
  58. -- 
  59. -----------------------------------------
  60. Lawrence Kirby | fred@genesis.demon.co.uk
  61. Wilts, England | 70734.126@compuserve.com
  62. -----------------------------------------
  63.